# -*- coding: utf-8 -*-
# @Time    : 2020/3/12 下午6:06
# @Author  : lilong


"""
执行顺序：类变量——>__new__()——>__init__()
"""


class MyBeautifulGril(object):
    """单例模式实现一"""

    print("开始类属性初始化。。。。。且只执行一次")

    # 私有类属性
    __instance = None
    __isFirstInit = False

    def __new__(cls, name):
        print("__new__() 执行。。。。")
        if not cls.__instance:
            # 第一次调用该类，先进行类变量的初始化，然后进行实例初始化
            MyBeautifulGril.__instance = super().__new__(cls)
        return cls.__instance

    def __init__(self, name):
        if not self.__isFirstInit:
            self.__name = name
            print("遇见" + name + "，我一见钟情！")
            MyBeautifulGril.__isFirstInit = True
        else:
            print("遇见" + name + "，我置若罔闻！")

    def showMyHeart(self):
        print(self.__name + "就我心中的唯一！")


def TestLove():

    jenny = MyBeautifulGril("Jenny")
    jenny.showMyHeart()

    kimi = MyBeautifulGril("Kimi")
    kimi.showMyHeart()

    print("id(jenny):", id(jenny), " id(kimi):", id(kimi))


TestLove()
